<!DOCTYPE html>


  <html class="dark page-post">


<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  
  <title>基于gulp的工作流配置 | Poetry&#39;s Blog</title>

  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

  
    <meta name="keywords" content="gulp,">
  

  <meta name="description" content="配置一套基于gulp的工作流，满足日常的基本开发。">
<meta name="keywords" content="gulp">
<meta property="og:type" content="article">
<meta property="og:title" content="基于gulp的工作流配置">
<meta property="og:url" content="http://blog.poetries.top/2017/01/21/gulp-works/index.html">
<meta property="og:site_name" content="Poetry&#39;s Blog">
<meta property="og:description" content="配置一套基于gulp的工作流，满足日常的基本开发。">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://poetries1.gitee.io/img-repo/2019/10/221.png">
<meta property="og:updated_time" content="2020-08-15T04:25:31.910Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="基于gulp的工作流配置">
<meta name="twitter:description" content="配置一套基于gulp的工作流，满足日常的基本开发。">
<meta name="twitter:image" content="https://poetries1.gitee.io/img-repo/2019/10/221.png">

  

  
    <link rel="icon" href="/favicon.ico">
  

  <link href="/css/styles.css?v=c114cbeddx" rel="stylesheet">
<link href="/css/other.css?v=c114cbeddx" rel="stylesheet">


  
    <link rel="stylesheet" href="/css/personal-style.css">
  

  

  
  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?40b1f89aa80f2527b3db779c6898c879";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>


  
  <script type="text/javascript">
	(function(){
	    var bp = document.createElement('script');
	    var curProtocol = window.location.protocol.split(':')[0];
	    if (curProtocol === 'https') {
	        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
	    }
	    else {
	        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
	    }
	    var s = document.getElementsByTagName("script")[0];
	    s.parentNode.insertBefore(bp, s);
	})();
  </script>



  
    <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <link rel="stylesheet" href="//cdn.bootcss.com/font-awesome/4.3.0/css/font-awesome.min.css">
  

  <!-- 聊天系统 -->
  
    
   <link type="text/css" rel="stylesheet" href="/renxi/default.css">
   <style>
      #modal {
        position: static !important;
      }
      .filter {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        background: #fe5757;
        animation: colorChange 30s ease-in-out infinite;
        animation-fill-mode: both;
        mix-blend-mode: overlay;
      }
  
      @keyframes colorChange {
        0%, 100% {
            opacity: 0;
        }
        50% {
            opacity: .9;
        }
      }
   </style>
</head>
</html>
<body>
  
  
    <span id="toolbox-mobile" class="toolbox-mobile">导航</span>
  

  <div class="post-header CENTER">
   
  <div class="toolbox">
    <a class="toolbox-entry" href="/">
      <span class="toolbox-entry-text">导航</span>
      <i class="icon-angle-down"></i>
      <i class="icon-home"></i>
    </a>
    <ul class="list-toolbox">
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/archives/"
            rel="noopener noreferrer"
            target="_self"
            >
            博客
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/categories/"
            rel="noopener noreferrer"
            target="_self"
            >
            分类
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/tags/"
            rel="noopener noreferrer"
            target="_self"
            >
            标签
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/search/"
            rel="noopener noreferrer"
            target="_self"
            >
            搜索
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/link/"
            rel="noopener noreferrer"
            target="_self"
            >
            友链
          </a>
        </li>
      
        <li class="item-toolbox">
          <a
            class="CIRCLE"
            href="/about/"
            rel="noopener noreferrer"
            target="_self"
            >
            关于
          </a>
        </li>
      
    </ul>
  </div>


</div>


  <div id="toc" class="toc-article">
    <strong class="toc-title">文章目录<i class="iconfont toc-title" style="display:inline-block;color:#87998d;width:20px;height:20px;">&#xf004b;</i></strong>
    <ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#一、目录结构"><span class="toc-text">一、目录结构</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#二、-package-json"><span class="toc-text">二、 package.json</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#三、-gulpfile-js"><span class="toc-text">三、 gulpfile.js</span></a></li></ol>
  </div>
  




<div class="content content-post CENTER">
   <!-- canvas 彩带 -->
<canvas id="evanyou" width="1302" height="678" style="position: fixed;width: 100%;height: 100%;top: 0;left:0;z-index:-1;"></canvas>

<article id="post-gulp-works" class="article article-type-post" itemprop="blogPost">
  <header class="article-header" style="position:relative;">
    <h1 class="post-title">基于gulp的工作流配置</h1>

    <div class="article-meta">
      <span>
        <i class="icon-calendar"></i>
        <span>2017.01.21</span>
      </span>

      
        <span class="article-author">
          <i class="icon-user"></i>
          <span>Poetry</span>
        </span>
      

      
  <span class="article-category">
    <i class="icon-list"></i>
    <a class="article-category-link" href="/categories/Build/">Build</a>
  </span>



      

      
      <i class="fa fa-eye"></i> 
        <span id="busuanzi_container_page_pv">
           &nbsp热度 <span id="busuanzi_value_page_pv">
           <i class="fa fa-spinner fa-spin"></i></span>℃
        </span>
      
      
       
          <span class="post-count">
            <i class="fa fa-file-word-o"></i>&nbsp
            <span>字数统计 1.3k字</span>
          </span>

          <span class="post-count">
            <i class="fa fa-columns"></i>&nbsp
            <span>阅读时长 6分</span>
          </span>
      
      
    </div>

    <i class="iconfont" id="toc-eye" style="display:inline-block;color:#b36619;position:absolute;top:0;right:0;cursor:pointer;
    font-size: 24px;">&#xe61c;</i>

  </header>

  <div class="article-content">
    
      <div id="container">
        <blockquote>
<p>配置一套基于<code>gulp</code>的工作流，满足日常的基本开发。</p>
</blockquote>
<a id="more"></a>
<h3 id="一、目录结构"><a href="#一、目录结构" class="headerlink" title="一、目录结构"></a>一、目录结构</h3><p><img src="https://poetries1.gitee.io/img-repo/2019/10/221.png" alt></p>
<h3 id="二、-package-json"><a href="#二、-package-json" class="headerlink" title="二、 package.json"></a>二、 package.json</h3><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line">&#123;</span><br><span class="line">  <span class="string">"name"</span>: <span class="string">"gulp-project"</span>,</span><br><span class="line">  <span class="string">"scripts"</span>: &#123;</span><br><span class="line">    <span class="string">"dev"</span>: <span class="string">"gulp dev"</span>, <span class="comment">//npm run dev   开发</span></span><br><span class="line">    <span class="string">"build"</span>: <span class="string">"gulp build"</span>, <span class="comment">//npm run build   发布</span></span><br><span class="line">    <span class="string">"upload"</span>: <span class="string">"gulp upload"</span>, <span class="comment">//npm run upload 上传服务器 </span></span><br><span class="line">    <span class="string">"zip"</span>: <span class="string">"gulp zip"</span> <span class="comment">////npm run zip 打包文件</span></span><br><span class="line">  &#125;,</span><br><span class="line">  <span class="string">"devDependencies"</span>: &#123;</span><br><span class="line">    <span class="string">"babel-preset-es2015"</span>: <span class="string">"^6.22.0"</span>, <span class="comment">//编译es6</span></span><br><span class="line">    <span class="string">"browser-sync"</span>: <span class="string">"^2.15.0"</span>,  <span class="comment">//监听改动刷新</span></span><br><span class="line">    <span class="string">"gulp"</span>: <span class="string">"^3.9.1"</span>, <span class="comment">//gulp</span></span><br><span class="line">    <span class="string">"gulp-autoprefixer"</span>: <span class="string">"^3.1.1"</span>, <span class="comment">//补齐css浏览器前缀</span></span><br><span class="line">    <span class="string">"gulp-babel"</span>: <span class="string">"^6.1.2"</span>, <span class="comment">// Es6</span></span><br><span class="line">    <span class="string">"gulp-clean"</span>: <span class="string">"^0.3.2"</span>, <span class="comment">//删除文件</span></span><br><span class="line">    <span class="string">"gulp-clean-css"</span>: <span class="string">"^2.0.12"</span>, <span class="comment">//css压缩，gulp-minify-css不更新了</span></span><br><span class="line">    <span class="string">"gulp-concat"</span>: <span class="string">"^2.6.0"</span>,<span class="comment">//合并文件</span></span><br><span class="line">    <span class="string">"gulp-ftp"</span>: <span class="string">"^1.1.0"</span>,<span class="comment">//提交到ftp服务器</span></span><br><span class="line">    <span class="string">"gulp-git"</span>: <span class="string">"^1.11.3"</span>,<span class="comment">//提交到git</span></span><br><span class="line">    <span class="string">"gulp-htmlmin"</span>: <span class="string">"^2.0.0"</span>,<span class="comment">//压缩html</span></span><br><span class="line">    <span class="string">"gulp-imagemin"</span>: <span class="string">"^3.0.3"</span>,<span class="comment">//压缩图片</span></span><br><span class="line">    <span class="string">"gulp-rename"</span>: <span class="string">"^1.2.2"</span>,<span class="comment">//重命名文件</span></span><br><span class="line">    <span class="string">"gulp-rev-append"</span>: <span class="string">"^0.1.6"</span>, <span class="comment">//添加MD5版本号，这里改成了时间戳</span></span><br><span class="line">    <span class="string">"gulp-sass"</span>: <span class="string">"^2.3.2"</span>,<span class="comment">//编译SASS</span></span><br><span class="line">    <span class="string">"gulp-uglify"</span>: <span class="string">"^2.0.0"</span>,<span class="comment">//js压缩</span></span><br><span class="line">    <span class="string">"gulp-util"</span>: <span class="string">"^3.0.7"</span>, <span class="comment">//说是ftp配套用的，看了下是包装了些常用函数</span></span><br><span class="line">    <span class="string">"gulp-zip"</span>: <span class="string">"^3.2.0"</span> <span class="comment">// 打包文件</span></span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h3 id="三、-gulpfile-js"><a href="#三、-gulpfile-js" class="headerlink" title="三、 gulpfile.js"></a>三、 gulpfile.js</h3><figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">//组件</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> gulp = <span class="built_in">require</span>(<span class="string">'gulp'</span>),</span><br><span class="line">	browserSync = <span class="built_in">require</span>(<span class="string">'browser-sync'</span>).create(), <span class="comment">//监听刷新</span></span><br><span class="line">    reload = browserSync.reload,</span><br><span class="line">    ftp = <span class="built_in">require</span>(<span class="string">'gulp-ftp'</span>), <span class="comment">// ftp上传</span></span><br><span class="line">    gutil = <span class="built_in">require</span>(<span class="string">'gulp-util'</span>),</span><br><span class="line">    sass = <span class="built_in">require</span>(<span class="string">'gulp-sass'</span>), <span class="comment">// sass</span></span><br><span class="line">    cleancss = <span class="built_in">require</span>(<span class="string">'gulp-clean-css'</span>), <span class="comment">// CSS压缩</span></span><br><span class="line">    autoprefixer = <span class="built_in">require</span>(<span class="string">"gulp-autoprefixer"</span>),</span><br><span class="line">    uglify = <span class="built_in">require</span>(<span class="string">'gulp-uglify'</span>), <span class="comment">// js压缩</span></span><br><span class="line">    concat = <span class="built_in">require</span>(<span class="string">'gulp-concat'</span>), <span class="comment">// 合并文件</span></span><br><span class="line">    rename = <span class="built_in">require</span>(<span class="string">'gulp-rename'</span>), <span class="comment">// 重命名</span></span><br><span class="line">    clean = <span class="built_in">require</span>(<span class="string">'gulp-clean'</span>), <span class="comment">//清空文件夹</span></span><br><span class="line">    imagemin = <span class="built_in">require</span>(<span class="string">'gulp-imagemin'</span>), <span class="comment">//压缩图片</span></span><br><span class="line">    zip = <span class="built_in">require</span>(<span class="string">'gulp-zip'</span>), <span class="comment">//打包文件</span></span><br><span class="line">    rev = <span class="built_in">require</span>(<span class="string">'gulp-rev-append'</span>), <span class="comment">//添加MD5</span></span><br><span class="line">    htmlmin = <span class="built_in">require</span>(<span class="string">'gulp-htmlmin'</span>), <span class="comment">// 压缩html</span></span><br><span class="line">	git = <span class="built_in">require</span>(<span class="string">'gulp-git'</span>),     <span class="comment">//git</span></span><br><span class="line">	babel = <span class="built_in">require</span>(<span class="string">"gulp-babel"</span>); <span class="comment">//ES6 转es5</span></span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">// =========== 开发构建流程 [多文件输出] ==============</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//dev</span></span><br><span class="line">gulp.task(<span class="string">'sass:dev'</span>, () =&gt; &#123;</span><br><span class="line">    gulp.src(<span class="string">'src/sass/*.scss'</span>)</span><br><span class="line">        .pipe(sass())</span><br><span class="line">        .pipe(gulp.dest(<span class="string">'src/css/'</span>))</span><br><span class="line">        .pipe(reload(&#123; <span class="attr">stream</span>: <span class="literal">true</span> &#125;))</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 合并、重命名css</span></span><br><span class="line">gulp.task(<span class="string">'css:dev'</span>, [<span class="string">'sass:dev'</span>], () =&gt; &#123;</span><br><span class="line">    gulp.src([<span class="string">'src/css/*.css'</span>, <span class="string">'!src/css/areaMap.css'</span>])</span><br><span class="line">        .pipe(concat(<span class="string">'all.css'</span>))</span><br><span class="line">        .pipe(gulp.dest(<span class="string">'dist/css/'</span>))</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 合并、重命名js</span></span><br><span class="line">gulp.task(<span class="string">'js:dev'</span>, () =&gt; &#123;</span><br><span class="line">    gulp.src(<span class="string">'src/js/*.js'</span>)</span><br><span class="line">    	.pipe(babel(&#123;</span><br><span class="line">		      	 	presets: [<span class="string">'es2015'</span>]</span><br><span class="line">     			&#125;)) <span class="comment">//ES6转ES5</span></span><br><span class="line">        <span class="comment">//.pipe(concat('all.js')) 开发阶段分开输出js文件</span></span><br><span class="line">        .pipe(gulp.dest(<span class="string">'dist/js/'</span>))</span><br><span class="line">        .pipe(reload(&#123; <span class="attr">stream</span>: <span class="literal">true</span> &#125;))</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// HTML</span></span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">'html:dev'</span>, () =&gt; &#123;</span><br><span class="line">    gulp.src(<span class="string">'src/tpl/*.html'</span>)</span><br><span class="line">        .pipe(gulp.dest(<span class="string">'dist'</span>))</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 将lib的库文件对应到指定位置</span></span><br><span class="line">gulp.task(<span class="string">'lib:dev'</span>, () =&gt; &#123;</span><br><span class="line">    gulp.src(<span class="string">'./src/lib/*'</span>)</span><br><span class="line">        .pipe(gulp.dest(<span class="string">'./dist/lib/'</span>));</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">//开发构建</span></span><br><span class="line">gulp.task(<span class="string">'dev'</span>, [<span class="string">'css:dev'</span>, <span class="string">'js:dev'</span>, <span class="string">'html:dev'</span>, <span class="string">'img'</span>,<span class="string">'copyFonts'</span>,<span class="string">'lib'</span>], () =&gt; &#123;</span><br><span class="line">    browserSync.init(&#123;</span><br><span class="line">        server: &#123;</span><br><span class="line">            baseDir: <span class="string">"dist"</span> <span class="comment">// 设置服务器的根目录为dist目录</span></span><br><span class="line">        &#125;,</span><br><span class="line">        notify: <span class="literal">false</span> <span class="comment">// 开启静默模式</span></span><br><span class="line">    &#125;);</span><br><span class="line">    <span class="comment">// 我们使用gulp的文件监听功能，来实时编译修改过后的文件</span></span><br><span class="line"></span><br><span class="line">    gulp.watch(<span class="string">'src/js/*.js'</span>, [<span class="string">'js:dev'</span>]);</span><br><span class="line">    gulp.watch(<span class="string">'src/sass/*.scss'</span>, [<span class="string">'sass:dev'</span>]);</span><br><span class="line">    gulp.watch(<span class="string">'src/tpl/*.html'</span>, [<span class="string">'html:dev'</span>]);</span><br><span class="line">    gulp.watch(<span class="string">'src/fonts/**'</span>, [<span class="string">'copyFonts'</span>]);</span><br><span class="line">    gulp.watch(<span class="string">'src/images/**'</span>, [<span class="string">'img'</span>]);</span><br><span class="line">    gulp.watch(<span class="string">'src/lib/**'</span>, [<span class="string">'lib'</span>]);</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">// =========== 正式构建 build [单文件输出] ==============</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// sass解析</span></span><br><span class="line">gulp.task(<span class="string">'sass'</span>, () =&gt; &#123;</span><br><span class="line">    gulp.src(<span class="string">'src/sass/*.scss'</span>)</span><br><span class="line">        <span class="comment">//输出为压缩</span></span><br><span class="line">         .pipe(sass(&#123;</span><br><span class="line">             outputStyle: <span class="string">'compressed'</span></span><br><span class="line">         &#125;))</span><br><span class="line">        .pipe(sass())</span><br><span class="line">        .pipe(gulp.dest(<span class="string">'src/css/'</span>))</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 合并、压缩、重命名css</span></span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">'css'</span>, [<span class="string">'sass'</span>], () =&gt; &#123;</span><br><span class="line">    gulp.src([<span class="string">'src/css/*.css'</span>, <span class="string">'!src/css/areaMap.css'</span>])</span><br><span class="line">        .pipe(concat(<span class="string">'all.css'</span>))</span><br><span class="line">        .pipe(autoprefixer(&#123;</span><br><span class="line">            browsers: [<span class="string">'last 2 versions'</span>, <span class="string">'Android &gt;= 4.0'</span>],</span><br><span class="line">            cascade: <span class="literal">true</span>, <span class="comment">//是否美化属性值 默认：true 像这样：</span></span><br><span class="line">            remove: <span class="literal">false</span> <span class="comment">//是否去掉不必要的前缀 默认：true </span></span><br><span class="line">        &#125;))</span><br><span class="line">        .pipe(cleancss()) <span class="comment">//压缩css</span></span><br><span class="line">        .pipe(gulp.dest(<span class="string">'dist/css'</span>));</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 合并，压缩,重命名js文件</span></span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">'js'</span>, () =&gt; &#123;</span><br><span class="line">    gulp.src(<span class="string">'src/js/*.js'</span>)</span><br><span class="line">    	.pipe(babel(&#123;</span><br><span class="line">		      	 	presets: [<span class="string">'es2015'</span>]</span><br><span class="line">     			&#125;)) <span class="comment">//ES6转ES5</span></span><br><span class="line">        .pipe(concat(<span class="string">'all.js'</span>))</span><br><span class="line">        .pipe(uglify())</span><br><span class="line">        .pipe(gulp.dest(<span class="string">'dist/js'</span>));</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">// 压缩HTML</span></span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">'html'</span>, () =&gt; &#123;</span><br><span class="line">    gulp.src(<span class="string">'src/tpl/*.html'</span>)</span><br><span class="line">        .pipe(rev())<span class="comment">//记得在引用地址后面加后缀，插件原本是ver=@@hash ,这里改成了v=@@hash</span></span><br><span class="line">      <span class="comment">//&lt;link rel="stylesheet" href="css/all.css?v=@@hash"&gt;</span></span><br><span class="line">      <span class="comment">//&lt;script src="js/all.js?v=@@hash"&gt;&lt;/script&gt;</span></span><br><span class="line">        .pipe(htmlmin(&#123;</span><br><span class="line">            removeComments: <span class="literal">true</span>, <span class="comment">//清除HTML注释</span></span><br><span class="line">            collapseWhitespace: <span class="literal">true</span>, <span class="comment">//压缩HTML</span></span><br><span class="line">            collapseBooleanAttributes: <span class="literal">true</span>, <span class="comment">//省略布尔属性的值 &lt;input checked="true"/&gt; ==&gt; &lt;input /&gt;</span></span><br><span class="line">            removeEmptyAttributes: <span class="literal">true</span>, <span class="comment">//删除所有空格作属性值 &lt;input id="" /&gt; ==&gt; &lt;input /&gt;</span></span><br><span class="line">            removeScriptTypeAttributes: <span class="literal">true</span>, <span class="comment">//删除&lt;script&gt;的type="text/javascript"</span></span><br><span class="line">            removeStyleLinkTypeAttributes: <span class="literal">true</span>, <span class="comment">//删除&lt;style&gt;和&lt;link&gt;的type="text/css"</span></span><br><span class="line">            minifyJS: <span class="literal">true</span>, <span class="comment">//压缩页面JS</span></span><br><span class="line">            minifyCSS: <span class="literal">true</span> <span class="comment">//压缩页面CSS</span></span><br><span class="line">        &#125;))</span><br><span class="line">        .pipe(gulp.dest(<span class="string">'dist'</span>))</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">//压缩图片</span></span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">'img'</span>, () =&gt; &#123;</span><br><span class="line">    gulp.src(<span class="string">'src/images/*.&#123;png,jpg,gif,ico&#125;'</span>)</span><br><span class="line">        .pipe(imagemin(&#123;</span><br><span class="line">            optimizationLevel: <span class="number">5</span>, <span class="comment">//类型：Number  默认：3  取值范围：0-7（优化等级）</span></span><br><span class="line">            progressive: <span class="literal">true</span>, <span class="comment">//类型：Boolean 默认：false 无损压缩jpg图片</span></span><br><span class="line">            interlaced: <span class="literal">true</span>, <span class="comment">//类型：Boolean 默认：false 隔行扫描gif进行渲染</span></span><br><span class="line">            multipass: <span class="literal">true</span> <span class="comment">//类型：Boolean 默认：false 多次优化svg直到完全优化</span></span><br><span class="line">        &#125;))</span><br><span class="line">        .pipe(gulp.dest(<span class="string">'dist/images'</span>));</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">//字体文件</span></span><br><span class="line">gulp.task(<span class="string">'copyFonts'</span>, <span class="function"><span class="keyword">function</span> (<span class="params"></span>) </span>&#123;</span><br><span class="line">    gulp.src(<span class="string">'src/fonts/**/*'</span>)</span><br><span class="line">        .pipe(gulp.dest(<span class="string">'dist/fonts/'</span>))</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 清空图片、样式、js</span></span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">'clean'</span>, () =&gt; &#123;</span><br><span class="line">    gulp.src(<span class="string">'dist'</span>, &#123; <span class="attr">read</span>: <span class="literal">false</span> &#125;)</span><br><span class="line">        .pipe(clean(&#123; <span class="attr">force</span>: <span class="literal">true</span> &#125;));</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 将bower的库文件对应到指定位置</span></span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">'lib'</span>, () =&gt; &#123;</span><br><span class="line">    gulp.src(<span class="string">'/src/lib/*'</span>)</span><br><span class="line">        .pipe(gulp.dest(<span class="string">'/dist/lib/'</span>));</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="code"><pre><span class="line">// ================ 打包主体dist 文件夹 zip ====</span><br><span class="line"></span><br><span class="line">//打包主体dist 文件夹并按照时间重命名</span><br><span class="line">gulp.task(&apos;zip&apos;, function()&#123;</span><br><span class="line">      function checkTime(i) &#123;</span><br><span class="line">          if (i &lt; 10) &#123;</span><br><span class="line">              i = &quot;0&quot; + i</span><br><span class="line">          &#125;</span><br><span class="line">          return i</span><br><span class="line">      &#125;</span><br><span class="line">          </span><br><span class="line">      var d=new Date();</span><br><span class="line">      var year=d.getFullYear();</span><br><span class="line">      var month=checkTime(d.getMonth() + 1);</span><br><span class="line">      var day=checkTime(d.getDate());</span><br><span class="line">      var hour=checkTime(d.getHours());</span><br><span class="line">      var minute=checkTime(d.getMinutes());</span><br><span class="line"></span><br><span class="line">  return gulp.src(&apos;./dist/**&apos;)</span><br><span class="line">        .pipe(zip(year+month+day +hour+minute+&apos;.zip&apos;))</span><br><span class="line">        .pipe(gulp.dest(&apos;./zip&apos;));</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<figure class="highlight javascript"><table><tr><td class="code"><pre><span class="line"><span class="comment">//正式构建</span></span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">'build'</span>, [<span class="string">'clean'</span>,<span class="string">'css'</span>, <span class="string">'js'</span>, <span class="string">'img'</span>, <span class="string">'html'</span>,<span class="string">'copyFonts'</span>,<span class="string">'lib'</span>]);</span><br><span class="line"></span><br><span class="line"><span class="comment">// ================ 上传 upload ====</span></span><br><span class="line"></span><br><span class="line">gulp.task(<span class="string">'upload'</span>, () =&gt; &#123;</span><br><span class="line">    gulp.src(<span class="string">'dist/**'</span>)</span><br><span class="line">        .pipe(ftp(&#123;</span><br><span class="line">            host: <span class="string">'8.8.8.8'</span>, <span class="comment">// 远程主机ip</span></span><br><span class="line">            port: <span class="number">22</span>, <span class="comment">// 端口</span></span><br><span class="line">            user: <span class="string">'username'</span>, <span class="comment">// 帐号</span></span><br><span class="line">            pass: <span class="string">'password'</span>, <span class="comment">// 密码</span></span><br><span class="line">            remotePath: <span class="string">'/project'</span> <span class="comment">// 上传路径，不存在则新建</span></span><br><span class="line">        &#125;))</span><br><span class="line">        .pipe(gutil.noop())</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>
      </div>
    
  </div>

</article>

<button class="assist-btn2 circle" id="assist_btn2" title="点亮屏幕" style="left: 27px; top: 152px;">
  <i class="iconfont" style="display:inline-block;color:red;width:20px;height:20px;">&#xe61d;</i>
</button>
<button class="assist-btn1 circle" id="assist_btn1" title="关闭屏幕亮度" style="left: 27px; top: 152px;">
  <i class="iconfont toc-title" style="display:inline-block;color:red;width:20px;height:20px;">&#xe61d;</i>
</button>


<script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>	

<script src="https://my.openwrite.cn/js/readmore.js" type="text/javascript"></script>
<script>
  const btw = new BTWPlugin();
  btw.init({
    id: "container",
    blogId: "22699-1592137983091-414",
    name: "前端进阶之旅",
    qrcode: "https://poetries1.gitee.io/img-repo/2020/06/qrcode.jpg",
    keyword: "3a3b3c",
  });
</script>

<script type="text/javascript">

// white theme
var body = {color: "#555", background: "#000"};
var a_tag = {color: "#222"};
var header = { background: "#222"};
var logo_line_i = {background: "#222"};
// var post_code = {background: "#eee", color: "#222"};

function switch_theme() {
 $("body").css(body);
 $("a:not('.links-of-author-item a, .site-state-item a, .site-state-posts a, .feed-link a, .motion-element a, .post-tags a, .show-commit-cls a, #donate_board a')").css(a_tag);
 $(".header, .footer").css(header);
 $(".logo-line-before i, .logo-line-after i").css(logo_line_i);
 //$(".post code").css(post_code);
 $("#idhyt-surprise-ball #idhyt-surprise-ball-animation .drag").css(a_tag);
 $(".post-title-link, .posts-expand .post-meta, .post-comments-count, .disqus-comment-count, .post-category a, .post-nav-next a, .post-nav-item a").css(a_tag);
 
 // $("code").css({color: '#c5c8c6', background: '#1d1f21'});
 //$("#assist_btn1").hide(1500);
}

$(function () {
$("#assist_btn2").css("display","none");
 $("#assist_btn1").click(function() {
     switch_theme();
$("div#toc.toc-article").css({
 "background":"#eaeaea",
 "opacity":1
});
$(".toc-article ol").show();
$("#toc.toc-article .toc-title").css("color","#a98602");
$("#assist_btn1").css("display","none");
$("#assist_btn2").css("display","block");
 });
$("#assist_btn2").click(function() {
$("#assist_btn2").css("display","none");
$("#assist_btn1").css("display","block");
$("body").css("background","url(http://www.miaov.com/static/ie/images/news/bg.png)")
     $(".header, .footer").css("background","url(http://www.miaov.com/static/ie/images/news/bg.png)")
$(".toc-article ol").toggle(1000);
 });
});


//背景随机

var Y, O, E, L, B, C, T, z, N, S, A, I;
!function() {
var e = function() {
for (O.clearRect(0, 0, L, B), T = [{
x: 0,
y: .7 * B + C
}, {
x: 0,
y: .7 * B - C
}]; T[1].x < L + C;) t(T[0], T[1])
}, t = function(e, t) {
O.beginPath(), O.moveTo(e.x, e.y), O.lineTo(t.x, t.y);
var n = t.x + (2 * I() - .25) * C,
 r = a(t.y);
O.lineTo(n, r), O.closePath(), N -= S / -50, O.fillStyle = "#" + (127 * A(N) + 128 << 16 | 127 * A(N + S / 3) + 128 << 8 | 127 * A(N + S / 3 * 2) + 128).toString(16), O.fill(), T[0] = T[1], T[1] = {
 x: n,
 y: r
}
}, a = function n(e) {
var t = e + (2 * I() - 1.1) * C;
return t > B || t < 0 ? n(e) : t
};
Y = document.getElementById("evanyou"), O = Y.getContext("2d"), E = window.devicePixelRatio || 1, L = window.innerWidth, B = window.innerHeight, C = 90, z = Math, N = 0, S = 2 * z.PI, A = z.cos, I = z.random, Y.width = L * E, Y.height = B * E, O.scale(E, E), O.globalAlpha = .6, document.onclick = e, document.ontouchstart = e, e()
}()

   
$("#toc-eye").click(function(){
$("#toc.toc-article").toggle(1000);
});

</script>


   
  <div class="text-center donation">
    <div class="inner-donation">
      <span class="btn-donation">支持一下</span>
      <div class="donation-body">
        <div class="tip text-center">扫一扫，支持poetries</div>
        <ul>
        
          <li class="item">
            
              <span>微信扫一扫</span>
            
            <img src="/images/weixin.jpg" alt="">
          </li>
        
          <li class="item">
            
              <span>支付宝扫一扫</span>
            
            <img src="/images/zhifubao.jpg" alt="">
          </li>
        
        </ul>
      </div>
    </div>
  </div>


   
  <div class="box-prev-next clearfix">
    <a class="show pull-left" href="/2017/01/14/webpack-summary/">
        <i class="icon icon-angle-left"></i>
    </a>
    <a class="show pull-right" href="/2017/02/04/es6-new-property/">
        <i class="icon icon-angle-right"></i>
    </a>
  </div>




</div>


  <a id="backTop" class="back-top">
    <i class="icon-angle-up"></i>
  </a>




  <div class="modal" id="modal">
  <span id="cover" class="cover hide"></span>
  <div id="modal-dialog" class="modal-dialog hide-dialog">
    <div class="modal-header">
      <span id="close" class="btn-close">关闭</span>
    </div>
    <hr>
    <div class="modal-body">
      <ul class="list-toolbox">
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/archives/"
              rel="noopener noreferrer"
              target="_self"
              >
              博客
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/categories/"
              rel="noopener noreferrer"
              target="_self"
              >
              分类
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/tags/"
              rel="noopener noreferrer"
              target="_self"
              >
              标签
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/search/"
              rel="noopener noreferrer"
              target="_self"
              >
              搜索
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/link/"
              rel="noopener noreferrer"
              target="_self"
              >
              友链
            </a>
          </li>
        
          <li class="item-toolbox">
            <a
              class="CIRCLE"
              href="/about/"
              rel="noopener noreferrer"
              target="_self"
              >
              关于
            </a>
          </li>
        
      </ul>

    </div>
  </div>
</div>



  
      <div class="fexo-comments comments-post">
    

    

    
    

    

    
    

    

<!-- Gitalk评论插件通用代码 -->
<div id="gitalk-container"></div>

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.css">
<script src="https://cdn.jsdelivr.net/npm/gitalk@1/dist/gitalk.min.js"></script>
<script>
const gitalk = new Gitalk({
  clientID: '5567a2c4abb858009d96',
  clientSecret: 'b9039ec056cf5c2346b3cdb63308a28c163f91e5',
  repo: 'poetries.github.io',
  owner: 'poetries',
  // 在这里设置一下截取前50个字符串, 这是因为 github 对 label 的长度有了要求, 如果超过
  // 50个字符串则会报错.
  // id: location.pathname.split('/').pop().substring(0, 49),
  id: location.pathname,
  admin: ['poetries'],
  // facebook-like distraction free mode
  distractionFreeMode: false
})
gitalk.render('gitalk-container')
</script>
<!-- Gitalk代码结束 -->



  </div>

  

  <script type="text/javascript">
  function loadScript(url, callback) {
    var script = document.createElement('script')
    script.type = 'text/javascript';

    if (script.readyState) { //IE
      script.onreadystatechange = function() {
        if (script.readyState == 'loaded' ||
          script.readyState == 'complete') {
          script.onreadystatechange = null;
          callback();
        }
      };
    } else { //Others
      script.onload = function() {
        callback();
      };
    }

    script.src = url;
    document.getElementsByTagName('head')[0].appendChild(script);
  }

  window.onload = function() {
    loadScript('/js/bundle.js?235683', function() {
      // load success
    });
  }
</script>


  <!-- 页面点击小红心 -->
  <script type="text/javascript" src="/js/clicklove.js"></script>
 
  
</body>
</html>
